Skip to content

feat: Smart route merging to prevent web.php overwrite during Breeze installation#477

Closed
AlbinXXX wants to merge 1 commit intolaravel:2.xfrom
AlbinXXX:2.x
Closed

feat: Smart route merging to prevent web.php overwrite during Breeze installation#477
AlbinXXX wants to merge 1 commit intolaravel:2.xfrom
AlbinXXX:2.x

Conversation

@AlbinXXX
Copy link

@AlbinXXX AlbinXXX commented Dec 9, 2025

Problem

When installing Laravel Breeze on a project, the breeze:install command completely overwrites the routes/web.php file, destroying any custom routes the developer may have already defined. This causes:

  • Loss of developer work
  • Breaking of existing application functionality
  • Poor developer experience
  • Manual restoration required

Solution

Implemented Smart Route Merging that intelligently detects whether the existing web.php contains default Laravel scaffold content or custom routes, and acts accordingly:

Scenario Behavior
Fresh Laravel project (default web.php) Complete replacement (preserves current behavior)
Custom routes detected in web.php Creates backup, merges Breeze routes while preserving existing routes
--force flag used Complete replacement regardless of content
Running installation twice Idempotent - no duplicate routes added

Changes Made

Files Modified

  • src/Console/InstallCommand.php - Added smart merging helper methods
  • src/Console/InstallsBladeStack.php - Updated to use smart merging
  • src/Console/InstallsApiStack.php - Updated to use smart merging
  • src/Console/InstallsInertiaStacks.php - Updated to use smart merging (Vue & React)
  • src/Console/InstallsLivewireStack.php - Updated to use smart merging

New Features

  1. --force flag - Allows explicit complete overwrite when desired
  2. Default scaffold detection - Identifies if web.php is the default Laravel template
  3. Automatic backup - Creates timestamped backup (web.php.backup.YYYY-MM-DD-HHMMSS) before merging
  4. Smart use statement injection - Adds required imports without duplicates
  5. Idempotent route injection - Checks for existing routes before adding
  6. Stack-specific routes - Correctly handles different route patterns for Blade, Inertia, Livewire, and API stacks

- Add --force flag to allow explicit overwrite when desired
- Detect default Laravel web.php scaffold vs custom routes
- Merge Breeze routes into existing web.php when custom routes detected
- Create timestamped backup before merging
- Ensure idempotency (running twice won't duplicate routes)
- Add required use statements without duplicates
- Apply to all stacks: Blade, API, Inertia (Vue/React), Livewire

Fixes issue where breeze:install would overwrite existing custom routes
in routes/web.php, causing loss of developer work.
@AlbinXXX
Copy link
Author

AlbinXXX commented Dec 9, 2025

Why? This is a bug me any my professor at uni where discussing.

@AlbinXXX AlbinXXX changed the title Pull Request: Fix Template Preview to Use Real Microsite Data feat: Smart route merging to prevent web.php overwrite during Breeze installation Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants